#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int t, n, a[N]; 
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        long long ans = 0;
        for (int i = 0; i < (1 << n); i++) {
            long long cnt = 0;
            int l0 = -1, l1 = -1;
            for (int j = 0; j < 15; j++) {
                if ((i >> j) & 1) {
                    if (l1 >= 0 && a[l1] == a[j]) {
                        cnt = 1ll * a[j] + cnt;
                    }
                    l1 = j;
                } else {
                    if (l0 >= 0 && a[l0] == a[j]) {
                        cnt = 1ll * a[j] + cnt;
                    }
                    l0 = j;
                }
            }
            ans = max(ans, cnt);
        }
        printf("%lld\n", ans);
    }
    return 0;
}